//
//  SXPTabbarController.m
//  oc_weibo
//
//  Created by shixinPeng on 16/3/2.
//  Copyright © 2016年 shixinPeng. All rights reserved.
//

#import "SXPTabbarController.h"
#import "SXPHomeViewController.h"
#import "SXPFindViewController.h"
#import "SXPMessageViewController.h"
#import "SXPSettingViewController.h"
#import "SXPtabBar.h"


@interface SXPTabbarController ()

@end

@implementation SXPTabbarController

- (void)viewDidLoad {
    [super viewDidLoad];

    //替换系统的tabar
    SXPtabBar *tabbar  = [[SXPtabBar alloc]init];
    
    //self.tabBar = tabbar;
    //利用kvc替换掉系统的tabBar
    [self setValue:tabbar forKey:@"tabBar"];
    

    
  
    
    
    
    [self addchildView];
    
}
/**
 *  添加控制器的方法
 */
-(void)addchildView {
    
    //添加首页界面
    SXPHomeViewController *home = [[SXPHomeViewController alloc]init];
    
    [self addChildViewWith:home andTilteString:@"首页" andImageString:@"tabbar_home"];
    
    //添加消息界面
    SXPMessageViewController *msg = [[SXPMessageViewController alloc]init];
    
    [self addChildViewWith:msg andTilteString:@"信息" andImageString:@"tabbar_message_center"];
    
    //添加发现界面
    SXPFindViewController *find = [[SXPFindViewController alloc]init];
    
    [self addChildViewWith:find andTilteString:@"发现" andImageString:@"tabbar_discover"];
    
    //添加设置界面
    SXPSettingViewController *seTTing = [[SXPSettingViewController alloc]init];
    
    [self addChildViewWith:seTTing andTilteString:@"设置" andImageString:@"tabbar_profile"];
    
    
}
/**
 *  添加控制器的方法
 */
-(void)addChildViewWith:(UIViewController *)vc andTilteString:(NSString *)titleStr andImageString:(NSString *)imageStr {
    //设置主题
    vc.title = titleStr;
    
    //设置图片
    vc.tabBarItem.image = [UIImage imageNamed:imageStr];
    
    vc.tabBarItem.selectedImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",imageStr]];
    
    //包装navgation
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
    
    //添加到tabbarcontroller中
    [self addChildViewController:nav];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
